In the latter half of the twentieth century, there began a phenomenon known as the information revolution. While the information revolution is a historical development broader in scope than any one event or machine, no single device has come to represent the information revolution more than the digital electronic computer. The development of computer systems has surely been a revolution. Each year, computer systems grow faster, store more data, and provide more applications to their users.
A modern computer system has the capability to store mountains of data, and using readily available networks can access even more data. Unfortunately, the capability of digital systems to store and access data has generally outpaced the ability of users to organize or understand the data. Considerable effort has been and continues to be devoted to developing improved techniques for organizing, searching, collating and presenting meaningful information to users from the voluminous data potentially available.
Computer systems may be used to support a variety of applications, but one common use is the maintenance of large databases, from which information may be obtained. Conceptually, a database may be viewed as one or more tables of information, each table having multiple entries (analogous to rows of a table), each entry having multiple respective data fields (analogous to columns of the table). In the case of some tables, the number of entries may be very large. A database management application typically includes capabilities for maintaining the data in the database in a consistent and coherent fashion, for executing queries against the data to obtain information of interest, and for generating and maintaining metadata which can be useful in executing queries, analyzing database performance, and so forth. For example, the database management application will often enforce constraints on particular data fields (data must be of a certain type, within a certain range, or bear a specified relationship with other data in the database), will automatically generate search strategies for executing queries against the data, or will automatically generate and maintain one or more indexes keyed by selective database fields whereby records can be conveniently located according to the value of the key field.
A database management application may be custom written for managing a particular database, but it is often a generic application intended to support different databases having widely varying parameters. The database management application will therefore support a variety of customization options to customize the application for a particular database. For example, the database management application will typically enable a privileged user (such as a system administrator) to define the number of tables in the database, the number of fields in each table, and the type of data in each field. The database management application will further provide an interface whereby other applications executing on behalf of users may invoke its functions to access data in the database.
Among the database customization capabilities offered by some database management applications is support for pre-defined customization functions involving the database, sometimes known as database triggers, or simply triggers. A database trigger is a procedure, defined according to some syntax supported by the database management application, which is executed whenever the corresponding trigger conditions are met. The trigger conditions are defined as part of the trigger. The trigger conditions must be chosen from among a limited range of conditions supported by the database management application. The database management application therefore monitors the trigger conditions, and if the conditions of any defined trigger are satisfied, executes (“fires”) the trigger. Triggers may be used, for example, to enforce data integrity constraints, to enforce business policies, to enforce security constraints, to back-up data, or for various other purposes.
Triggers have the advantage of offering a flexible, easily maintainable, centralized control mechanism for customizing the database. Because the trigger executes automatically whenever the pre-defined trigger conditions are met, it is not necessary for user applications which access the database to explicitly invoke the trigger or perform any of the trigger's functions. The trigger itself may contain any required conditional logic to perform the corresponding operation(s) only when required by the circumstances, so that all maintenance of conditions associated with performing an operation is handled in a single place.
Unfortunately, triggers can also impose a significant burden on system performance. There is considerable overhead involved in executing a trigger, i.e., in calling and initializing the trigger procedure. This overhead is incurred whenever the trigger is fired, whether it actually does anything or not. Many triggers are written to address circumstances which rarely arise or arise only with certain users and not others. It is not uncommon for a trigger to fire many times on behalf of a single executing application. In the majority of times these triggers are called, statements near the beginning of the trigger procedure determine that the trigger is inapplicable, and simply return without doing anything. In this case, the overhead burden has already been incurred.
It is possible to provide data structures and/or conditional logic for selectively enabling and disabling a trigger in order to reduce the instances of unnecessary trigger execution, but such mechanisms involve additional complexity and must be maintained consistent with any changes to the trigger or to the needs of the database to apply the trigger's function. Maintaining logic affecting the trigger's function in code or data structures external to the trigger defeats one of the major advantages of the trigger and increases the likelihood of unforeseen errors.
A need exists, not necessarily recognized, for improved techniques for managing database triggers, and in particular for techniques for reducing the instances of unnecessary trigger execution without incurring undue maintenance burdens.